package command

import (
	global "developer_tools/globals"
	"developer_tools/internal"
	"encoding/json"
	"os"
	"path"
)

var log_ = global.Logger

// CheckCmdIsContinuous checks if the given command is a continuous command by reading the configuration file and checking the list of continuous commands.
func CheckCmdIsContinuous(cmd string) bool {
	home, err := os.UserHomeDir()
	if err != nil {
		log_.Errorf("Failed to get user home directory: %v", err)
		return false
	}

	data, err := internal.ReadFile(path.Join(home, global.PwdUserSRPath, global.ConfigPath))
	if err != nil {
		log_.Errorf("Failed to read file: %v", err)
		return false
	}

	var continuousCommands map[string][]string
	err = json.Unmarshal(data, &continuousCommands)
	if err != nil {
		log_.Errorf("Failed to unmarshal JSON data: %v", err)
		return false
	}

	return internal.CheckIsContinuousCmd(cmd, continuousCommands)
}
